﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class RecipeItem
    {
        public static void insert(RecipeItemEntity recipeItem)
        {
            DbHelper.ExecuteNonQuery("p_RecipeItem_insert",
                recipeItem.ProductId,
                recipeItem.RecipeId
            );
        }

        public static void update(RecipeItemEntity recipeItem)
        {
            DbHelper.ExecuteNonQuery("p_RecipeItem_update",
                recipeItem.RciId,
                recipeItem.ProductId,
                recipeItem.RecipeId,
                recipeItem.InputDt
            );
        }

        public static void delete(int rciId)
        {
            DbHelper.ExecuteNonQuery("p_RecipeItem_delete", rciId);
        }

        public static void delByRecipeId(int recipeId)
        {
            DbHelper.ExecuteNonQuery("p_RecipeItem_Delete_By_RecipeId", recipeId);
        }

        public static RecipeItemEntity getById(int rciId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_recipeItem_getById", rciId);
            RecipeItemEntity recipeItem = new RecipeItemEntity();
            if (dr != null)
            {
                recipeItem.RciId = int.Parse(dr["rciId"].ToString());
                recipeItem.ProductId = int.Parse(dr["productId"].ToString());
                recipeItem.RecipeId = int.Parse(dr["recipeId"].ToString());
                recipeItem.InputDt = DateTime.Parse(dr["inputDt"].ToString());
            }
            return recipeItem;
        }
        public static DataTable listRecipeItemByRecipeId(int recipeId)
        {
            return DbHelper.ExecuteSqlDataTable(String.Format("SELECT *FROM dbo.vw_RecipeItem_list WHERE recipeId={0}", recipeId));
        }
    }
}